package com.example.yls.sqlhelper;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button btnOpen;
    private Button btnInsert;
    private StudbOpenHelper studbOpenHelper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnOpen=findViewById(R.id.btn_open);
        btnOpen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               /*studbOpenHelper=new StudbOpenHelper(MainActivity.this,
                        "stu.db",null,1);*/
                studbOpenHelper=new StudbOpenHelper(MainActivity.this,
                        "stu.db",null,3);
                SQLiteDatabase sqLiteDatabase=studbOpenHelper.getWritableDatabase();
            }
        });

        btnInsert=findViewById(R.id.btn_insert);
        btnInsert.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               SQLiteDatabase sqLiteDatabase=studbOpenHelper.getWritableDatabase();
                ContentValues values=new ContentValues();
                values.put("stuno","171001");
                values.put("name","liming");
                values.put("age",20);

                sqLiteDatabase.insert("student",null,values);
            }
        });
    }
}
